//
//  CheckFormController.m
//  PropertyMananger
//
//  Created by bh on 17/2/23.
//  Copyright © 2017年 BH. All rights reserved.
//

#import "CheckFormController.h"
#import "ElectricityMeterController.h"
#import "WaterMeterController.h"
#import "CheckFormCell.h"
@interface CheckFormController ()

@property (nonatomic,strong) NSArray * iconArray;

@end

@implementation CheckFormController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initTitleViewName:@"抄表"];
    
       
    [self createSegmentUI];
    
    self.iconArray = @[@"ico_meter_reading_ban",@"ico_meter_reading_room",@"ico_meter_reading_reading",@"ico_meter_reading_date"];
}
- (void)createSegmentUI{

    WaterMeterController * waterVC = [[WaterMeterController alloc]init];
    [self addChildViewController:waterVC];
    
    ElectricityMeterController * electricsVC = [[ElectricityMeterController alloc]init];
    [self addChildViewController:electricsVC];
    
    NSArray * controllers = @[waterVC,electricsVC];
    NSArray * titleArray = @[@"水表",@"电表"];
    
    self.bottomSView = [[SGSegmentedControlBottomView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    self.bottomSView.childViewController = controllers;
    self.bottomSView.backgroundColor = [UIColor clearColor];
    self.bottomSView.delegate = self;
    
    //_bottomView.scrollEnabled = NO;
    [self.view addSubview:self.bottomSView];
    
    self.topSView = [SGSegmentedControlStatic segmentedControlWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44) delegate:self childVcTitle:titleArray indicatorIsFull:NO];
    // 必须实现的方法
    [self.topSView SG_setUpSegmentedControlType:^(SGSegmentedControlStaticType *segmentedControlStaticType, NSArray *__autoreleasing *nomalImageArr, NSArray *__autoreleasing *selectedImageArr) {
        
    }];
    self.topSView.selectedIndex = 0;
    [self.view addSubview:self.topSView];
    
}
- (void)SGSegmentedControlStatic:(SGSegmentedControlStatic *)segmentedControlStatic didSelectTitleAtIndex:(NSInteger)index {
    NSLog(@"index - - %ld", (long)index);
    if (index == 1) {
        
         [MBProgressHUD showError:@"正在努力开发中" toView:self.view time:1.5];
    }
    // 计算滚动的位置
    CGFloat offsetX = index * self.view.frame.size.width;
    self.bottomSView.contentOffset = CGPointMake(offsetX, 0);
    [self.bottomSView showChildVCViewWithIndex:index outsideVC:self];
}

#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    // 计算滚动到哪一页
    NSInteger index = scrollView.contentOffset.x / scrollView.frame.size.width;
    
    // 1.添加子控制器view
    [self.bottomSView showChildVCViewWithIndex:index outsideVC:self];
    
    // 2.把对应的标题选中
    [self.topSView changeThePositionOfTheSelectedBtnWithScrollView:scrollView];
}
#pragma mark - TableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return self.iconArray.count;

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    CheckFormCell * cell = [CheckFormCell cellWithTableView:tableView];
    cell.iconImg.image = IMG(self.iconArray[indexPath.row]);
    
    return cell;

}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 50;

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
